/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.xulapa.ejb;

import br.com.xulapa.dao.MarcaDAO;
import br.com.xulapa.domain.Marca;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author brunolellis
 */
@Stateless
public class XulapaBean implements XulapaBeanRemote {

    @Inject
    private MarcaDAO marcaDAO;

    @PersistenceContext
    private EntityManager em;

    public void sayXulapa() {
        System.out.println("xulapaaaaaaaaa");
    }

    public Marca createMarca(Marca marca) {
        //marcaDAO.create(marca);
        em.persist(marca);
        return marca;
    }

    public List<Marca> findAllMarca() {
        //return marcaDAO.findAll();

        Query query = em.createNamedQuery("Marca.findAll");
        return query.getResultList();

    }

    public void updateMarca(Marca marca) {
        //marcaDAO.update(marca);
        em.merge(marca);
    }

    public Marca findMarcaById(int id) {
        Query query = em.createNamedQuery("Marca.findById");
        query.setParameter("id", id);

        return (Marca) query.getSingleResult();
    }

    public void deleteMarca(Long id) {
        Query query = em.createNamedQuery("Marca.removeById");
        query.setParameter("id", id);

        query.executeUpdate();

    }

}
